package com.chzc.fm.duotin.adapter.recyclerview;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.chzc.fm.duotin.R;
import com.chzc.fm.duotin.bean.mine.LikeBean;
import com.chzc.fm.duotin.utils.ImageUtil;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by BillSinla on 2016/7/1.
 */
public class LikeRecyclerAdapter extends RecyclerView.Adapter<LikeRecyclerAdapter.Holder>{

    private Context context;
    private LayoutInflater inflater;
    private List<LikeBean> likeBeans;

    public LikeRecyclerAdapter(Context context, List<LikeBean> likeBeens) {
        this.context = context;
        this.likeBeans = likeBeens;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.adapter_like_item, null);
        return new Holder(view);
    }

    @Override
    public void onBindViewHolder(Holder holder, int position) {
        ImageLoader.getInstance().displayImage(likeBeans.get(position).getImage_url(), holder.imageAvatar, ImageUtil.getRoundOptions());
        holder.textName.setText(likeBeans.get(position).getAlbum_title());
        holder.textDes.setText(likeBeans.get(position).getTitle());
    }

    @Override
    public int getItemCount() {
        return likeBeans != null ? likeBeans.size() : 0;
    }

    protected class Holder extends RecyclerView.ViewHolder {
        public ImageView imageAvatar;
        public TextView textName, textDes;
        public Holder(View itemView) {
            super(itemView);
            imageAvatar = (ImageView) itemView.findViewById(R.id.iv_like_avatar);
            textName = (TextView) itemView.findViewById(R.id.tv_like_name);
            textDes = (TextView) itemView.findViewById(R.id.tv_like_des);
        }
    }
}
